<?php


class UsersModel extends Model{

	public function checkLogin($username, $password)
	{
		$userInfo = $this->where(array('username' => $username))->find();

		if($userInfo != null){
			if($userInfo['password'] == $password){
				$user = array(
					'id' => $userInfo['id'],
					'username' => $username,
					'group_id' => $userInfo['group_id']
					);
				$_SESSION['current_user'] = $user;
				return 1;
			}else{
				return 0;
			}
		}
		return -1;
	}


	public function savePwd($id, $oldPassword, $newPassword)
	{
		# code...
		$data['oldPassword'] = $oldPassword;
		$user = $this->where( array('id' => $id, 'password' => $oldPassword) )->find();

		if($user){
			$res = $this->where('id='.$id)->setField("password", $newPassword);
			if($res){
				return 1;
			}else{
				return 0;
			}
		}

		return -1;
		
	}


}

?>